package com.ruoyi.material.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.MaterialReturnRequest;
import com.ruoyi.material.service.IMaterialReturnRequestService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊材退库管理Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@Controller
@RequestMapping("/material/return")
public class MaterialReturnRequestController extends BaseController
{
    private String prefix = "material/return";

    @Autowired
    private IMaterialReturnRequestService materialReturnRequestService;

    @RequiresPermissions("material:return:view")
    @GetMapping("/request")
    public String returnRequest()
    {
        return prefix + "/return";
    }

    /**
     * 查询焊材退库管理列表
     */
    @RequiresPermissions("material:return:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaterialReturnRequest materialReturnRequest)
    {
        startPage();
        List<MaterialReturnRequest> list = materialReturnRequestService.selectMaterialReturnRequestList(materialReturnRequest);
        return getDataTable(list);
    }

    /**
     * 导出焊材退库管理列表
     */
    @RequiresPermissions("material:return:export")
    @Log(title = "焊材退库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaterialReturnRequest materialReturnRequest)
    {
        List<MaterialReturnRequest> list = materialReturnRequestService.selectMaterialReturnRequestList(materialReturnRequest);
        ExcelUtil<MaterialReturnRequest> util = new ExcelUtil<MaterialReturnRequest>(MaterialReturnRequest.class);
        return util.exportExcel(list, "焊材退库管理数据");
    }

    /**
     * 新增焊材退库管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊材退库管理
     */
    @RequiresPermissions("material:return:add")
    @Log(title = "焊材退库管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialReturnRequest materialReturnRequest)
    {
        return toAjax(materialReturnRequestService.insertMaterialReturnRequest(materialReturnRequest));
    }

    /**
     * 修改焊材退库管理
     */
    @RequiresPermissions("material:return:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MaterialReturnRequest materialReturnRequest = materialReturnRequestService.selectMaterialReturnRequestById(id);
        mmap.put("materialReturnRequest", materialReturnRequest);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊材退库管理
     */
    @RequiresPermissions("material:return:edit")
    @Log(title = "焊材退库管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialReturnRequest materialReturnRequest)
    {
        return toAjax(materialReturnRequestService.updateMaterialReturnRequest(materialReturnRequest));
    }

    /**
     * 删除焊材退库管理
     */
    @RequiresPermissions("material:return:remove")
    @Log(title = "焊材退库管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(materialReturnRequestService.deleteMaterialReturnRequestByIds(ids));
    }
}
